layui.use(['table', 'form', 'jquery','laydate'], function() {
    let  table = layui.table;
    let  form = layui.form;
    let  $ = layui.jquery;

        let  cols = [
            [{
                    field: 'name',
                    title: '姓名',
                    unresize: true,
                    align: 'center'
                }, {
                    field: 'sex',
                    title: '性别',
                    unresize: true,
                    align: 'center'
                }, {
                    field: 'phone',
                    title: '电话',
                    unresize: true,
                    align: 'center'
                }, {
                    field: 'counselor_name',
                    title: '顾问',
                    unresize: true,
                    align: 'center'
                }, {
                    field: 'course_name',
                    title: '咨询课程',
                    unresize: true,
                    align: 'center'
                }, {
                    field: 'campus_name',
                    title: '校区',
                    unresize: true,
                    align: 'center'
                }, {
                    field: 'source_name',
                    title: '来源',
                    unresize: true,
                    align: 'center'
                }]
        ];
        table.render({
            elem: '#dataTable',
            data: [],
            page: true,
            cols: cols,
            skin: 'line',
            toolbar: ' ',
            done: function(res,curr,count) {
                var that = this.elem.next();
                if (res.data){
                    res.data.forEach((item,index) => {
                        var colorId = localStorage.getItem("theme-color")
                        if (index % 2 == 0) {
                             tr = that.find('.layui-table-box tbody tr[data-index='+ index +']').css('background-color',colourDeal(colorId));
                        } else {
                             tr = that.find('.layui-table-box tbody tr[data-index='+ index +']').css('background-color');
                        }
                    });
                }
            },
            defaultToolbar: [{
                title: '刷新',
                layEvent: 'refresh',
                icon: 'layui-icon-refresh',
            }, 'filter']
        });

    table.on('toolbar(dataTable)',function (obj) {
        if (obj.event === 'refresh') {
            window.refresh();
        }
    })

    form.on('submit(query)', function(data) {
        table.reload('dataTable', {
            url: 'checkPhone',
            where: data.field,
            page:{curr: 1}
        })
        return false;
    });

    //数据刷新
    window.refresh = function (param) {
        table.reload('dataTable');
    }
})

